#include<iostream>
#include<vector>

using std::pair;
using std::make_pair;
using std::vector;
using std::cin;
using std::cout;

const int white = 0;
const int grey = 1;
const int black = 2;

struct Graph {
    vector<vector<int> > graph;
    vector<int> color;
    Graph(vector<vector<int> > &graph) : graph(graph), color(vector<int> ()) {
        color.assign(graph.size(), white);
    }

    void remove_marks() {
        color.assign(graph.size(), white);
    }
};

class Visitor_bridges {
 private:
    vector<int> time_in;
    vector<int> f_up;
    int timer;
    vector<pair<int, int> > bridges;
 public:
    Visitor_bridges(int vertexes) :
        time_in(vector<int> (vertexes)),
        f_up(vector<int> (vertexes)),
        timer(0),
        bridges(vector<pair<int, int> >) {
    };

    void start(Graph &graph, int v) {
        graph.color[v] = grey;
        time_in[v] = timer;
        f_up[v] = timer;
        ++timer;
    }
    void enter_vertex(Graph &graph, int v, int to, int p) {
        if (to != p && graph.color[to] == white) {
            f_up[v] = std::min(f_up[v], time_in[to]);
        }
    }
    bool condition(Graph &graph, int to, int p) {
        return (to != p && graph.color[to] == white);
    }
    void leave_vertex(Graph &graph, int v, int to, int p) {
        if (to != p && graph.color[to] == white) {
            f_up[v] = std::min(f_up[v], f_up[to]);
            if (f_up[to] > time_in[v]) {
                bridges.push_back(make_pair(v, to));
            }
        }
    }
    void finish(Graph &graph, int v) {
        graph.color[v] = black;
    }
};


class Visitor_simple {
 public:
    Visitor_simple() {
    };
    void start(Graph &graph, int v) {
        graph.color[v] = grey;
    }
    void enter_vertex(Graph &graph, int v, int to, int p) {
    }
    bool condition(Graph &graph, int to, int p) {
        return graph.color[to] == white;
    }
    void leave_vertex(Graph &graph, int v, int to, int p) {
    }
    void finish(Graph &graph, int v) {
        graph.color[v] = black;
    }
};

template <typename Visitor>
void dfs(Graph &graph, int vertex, int parent, Visitor &visitor) {
    visitor.start(graph, vertex);
    for (int to : graph.graph[vertex]) {
        visitor.enter_vertex(graph, vertex, to, parent);
        if (visitor.condition(graph, to, parent)) {
            dfs(graph, to, vertex, visitor);
        }
        visitor.leave_vertex(graph, vertex, to, parent);
    }
    visitor.finish(graph, vertex);
}

int main() {
    int vertexes = 0;
    int edges = 0;
    cin >> vertexes >> edges;
    vector<vector<int>> adjacent_list(vertexes);
    for (int i = 0; i < edges; ++i) {
        int from = 0, to = 0;
        cin >> from >> to;
        adjacent_list[--from].push_back(--to);
    }
    Graph graph(adjacent_list);
    Visitor_bridges visitor(vertexes);
    dfs(graph, 0, -1, visitor);
    return 0;
}
